package net.kong.sns.rest.client.model;

import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;


/**
 * @author yk
 * @version $Id: FriendInfo.java,v 1.3 2009/08/04 07:13:46 yongkun Exp $
 */
public class FriendInfo extends AbstractJsonAppObject{
    private long userId;
    private String nickName;
    private boolean male;
    private boolean female;
    
    public enum Field {
        user_id, nickname, male, female;

        @Override
        public String toString() {
            return name().toLowerCase();
        }
    }
    public FriendInfo(){}
    public FriendInfo(long userId,String nickName,boolean male,boolean female){
        this.userId=userId;
        this.nickName=nickName;
        this.male=male;
        this.female=female;
    }
    public long getUserId() {
        return userId;
    }
    
    public void setUserId(long userId) {
        this.userId = userId;
    }
    
    public String getNickName() {
        return nickName;
    }
    
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
    
    public boolean isMale() {
        return male;
    }
    
    public void setMale(boolean male) {
        this.male = male;
    }
    
    public boolean isFemale() {
        return female;
    }
    
    public void setFemale(boolean female) {
        this.female = female;
    }

    @Override
    protected void processJsonObject(Map<String, Object> stringObjectMap) {
        if (stringObjectMap != null) {
            Set<String> fields = getInitializedFields();
            for (String fieldName : fields) {
                Object o = (Object) stringObjectMap.get(fieldName);
                if (o != null) {
                    if (fieldName.equals(Field.user_id.toString())) {
                        this.userId = ((Number) o).longValue();
                    }
                    else if (fieldName.equals(Field.nickname.toString())) {
                        this.nickName = (String) o;
                    }
                    else if (fieldName.equals(Field.male.toString())) {
                        this.male = (Boolean) o;
                    }
                    else if (fieldName.equals(Field.female.toString())) {
                        this.female = (Boolean) o;
                    }
                }
            }
        }
    }
    /**
     * @see java.lang.Object#equals(Object)
     */
    public boolean equals(Object object) {
        if (!(object instanceof FriendInfo)) {
            return false;
        }
        FriendInfo rhs = (FriendInfo) object;
        return new EqualsBuilder().append(this.female, rhs.female).append(this.nickName, rhs.nickName).append(this.male, rhs.male).append(
                this.userId, rhs.userId).isEquals();
    }
    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return new ToStringBuilder(this).append("userId", this.userId).append("initializedFields", this.getInitializedFields()).append("nickName",
                this.nickName).append("female", this.female).append("male", this.male).toString();
    }
}
